<template>
    <div class="sidebar">
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="sidebar.collapse"
            text-color="#000"           
            active-text-color="#ff0000"
            unique-opened
            router
        >
            <template v-for="item in items">
                <template v-if="item.subs">
                    <!-- 二级标题 -->
                    <el-sub-menu :index="item.index" :key="item.index" v-permiss="item.permiss">
                        <!-- icon+文字 -->
                        <template #title>
                            <el-icon>
                                <component :is="item.icon"></component>
                            </el-icon>
                            <span>{{ item.title }}</span>
                        </template>
                        <!-- 三级标题（若有可以添加） -->
                        <template v-for="(subItem,i) in item.subs" :key="i">
                            <el-sub-menu
                                v-if="subItem.subs"
                                :index="subItem.index"
                                :key="subItem.index"
                                v-permiss="item.permiss"
                            >
                                <template #title>{{ subItem.title }}</template>
                                <el-menu-item v-for="(threeItem, i) in subItem.subs" :key="i" :index="threeItem.index">
                                    {{ threeItem.title }}
                                </el-menu-item>
                            </el-sub-menu>
                            <el-menu-item v-else :index="subItem.index" v-permiss="item.permiss">
                                {{ subItem.title }}
                            </el-menu-item>
                        </template>
                    </el-sub-menu>
                </template>
                <!-- 显示一级标题 -->
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index" v-permiss="item.permiss">
                        <el-icon>
                            <component :is="item.icon"></component>
                        </el-icon>
                        <template #title>{{ item.title }}</template>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script setup lang="ts">
import { onMounted, reactive } from 'vue';
import { computed } from 'vue';
import { useSidebarStore } from '../../store/sidebar.js';
import { loadRouteLocation, useRoute } from 'vue-router';

const items = [
    {
        icon: 'User',
        index: '/Main',
        title: '个人中心',
        //permiss: '1',
    },
    {
        icon: 'Edit',
        index: '/accountmanage',
        title: '账户管理',
        //permiss: '2',
    },
    {
        icon: 'DocumentCopy',
        index: '',
        title: '签约用户',
        //permiss: '3',
        subs: [
            {
                index: '/FindUser',
                title: '用户查询',
                //permiss: '3',
            },
            {
                //index: '/BodyIndex',
                title: '用户详情',
                //permiss: '3',
            }
        ],
    },
    {
        icon: 'Clock',
        index: '/DoctorAppointment',
        title: '就诊预约',
    },
    {
        icon: 'Collection',
        index: '/ContectUser',
        title: '随访管理',
        //permiss: '11',
    },
    {
        icon: 'Warning',
        index: '/SignContect',
        title: '签约申请',
        //permiss: '13',
    },
    {
        icon: 'Service',
        index: '/HealthConseling',
        title: '健康咨询',
        //permiss: '14',
    },
    {
        icon: 'VideoCamera',
        index: '/DoctorVideo',
        title: '视频问诊',
        //permiss: '15',
    },
];
const route = useRoute();
const onRoutes = computed(() => {
    return route.path;
});

const sidebar = useSidebarStore();

const collapseChage = () => {
	sidebar.handleCollapse();
};

onMounted(() => {
	if (document.body.clientWidth < 1500) {
		collapseChage();
	}
});
</script>

<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 5px;
    top: 5px;
    bottom: 5px;
    overflow-y: scroll;
    border-radius: 10px;
    backdrop-filter: blur(2px);
    background: linear-gradient(to right bottom,rgba(255,255,255,0.6),rgba(255,255,255,0.3));
}
.sidebar::-webkit-scrollbar {
    width: 0px;
}
.sidebar-el-menu{
    background: linear-gradient(to right bottom,rgba(255,255,255,0.6),rgba(255,255,255,0.3));
    background-color: #084779; 
}

.sidebar-el-menu:not(.el-menu--collapse) {
    width: 213px;
}
.sidebar > ul {
    height: 100%;
    padding-top:50px;
}
</style>
